import numpy as np
import matplotlib.pyplot as plt
# with open("./Data1.txt", "r") as f:
#     i = list(map(lambda t: (sum(map(lambda x: float(x), t[1:-2].split(", ")))), f.readlines()))
#     plt.plot(i)
# plt.show()

with open("./save.txt", "r") as f:
    flag = False
    j = []
    for i in f.readlines():
        if flag:
            j.append(float(i[8:-2]))
            print(j)
        flag = not flag
class TurningDetected():
    def __init__(self):
        self.pre = 0
        self.k_buffer = np.zeros(5)
        self.k_point = 0
        self.t_pre = 0
        self.flag = False
    def get(self, angle):
        self.k_buffer[self.k_point] = abs((angle - self.pre + 180) % 360 - 180)
        t = 1.4 * self.k_buffer[(self.k_point + 3) % 5] - 0.4 * sum(self.k_buffer)
        t = t if t > 0 else 0
        l = t - self.t_pre
        self.k_point = 1 + self.k_point if self.k_point < 4 else 0
        self.t_pre = t
        self.pre = angle
        if self.flag:
            if l < 2:
                self.flag = False
            return 0
        else:
            if l > 6:
                self.flag = True
                return 1
            else:
                return 0
a = TurningDetected()
b = list(map(a.get, j))
print(j)
plt.plot(b)
plt.show()